package com.yunxun.coinmessage.controller;

import com.yunxun.coinmessage.dao.SubscribeDao;
import com.yunxun.coinmessage.entity.Subscribe;
import com.yunxun.coinmessage.entity.User;
import com.yunxun.coinmessage.service.SubscribeService;
import com.yunxun.coinmessage.templatedata.MsgResult;
import com.yunxun.coinmessage.service.UserService;
import com.yunxun.coinmessage.sqlvo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.rmi.server.InactiveGroupException;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/queryUserByPage")
    public String queryUserByPage(UserVO userVO,Model model){
        Integer total=userService.queryTotal();
        List<User> userList=userService.queryByPage(userVO);
        Integer totalPage=(total+19)/20;
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("total",total);
        model.addAttribute("userList",userList);
        return "user-list";
    }
    @RequestMapping("/queryUserByPage1")
    @ResponseBody
    public List<User> queryUserByPage1(UserVO userVO){
        List<User> userList=userService.queryByPage(userVO);
        return userList;
    }
    @RequestMapping("/queryUserByName")
    public String queryUserByName(String uname,Model model){
        int total=userService.queryTotalByName(uname);
        int totalPage=(total+9)/10;
        model.addAttribute("total",total);
        model.addAttribute("totalPage",totalPage);
        model.addAttribute("uname",uname);
        return "user-list";
    }
    @RequestMapping("/changeUserStatus")
    @ResponseBody
    public MsgResult changeUserStatus(User user){
        return userService.changeUserStatus(user);
    }

    @RequestMapping("/updateUserLevel")
    @ResponseBody
    public void updateUserLevel(User user){
        userService.updateUserLevel(user);
    }
}
